<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.mode</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_mode_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.4 Documentation</a></li><li>Spec</li><li>Spec - howl.mode</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.mode">howl.mode</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">[</span><span class="n">name</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="n">mode</span><span class="p">.</span><span class="n">names</span><span class="w"> </span><span class="k">when</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s1">'default'</span><span class="w"> </span><span class="p">]</span><span class="w">&#x000A;    </span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="n">name</span></pre>&#x000A;&#x000A;<h4 id="mode-instances-are-memoized">mode instances are memoized</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'same'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'again'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'same'</span><span class="p">),</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'once.again'</span></pre>&#x000A;&#x000A;<h4 id="mode-instances-automatically-have-their-.name-set">mode instances automatically have their .name set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'named'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'again'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'named'</span><span class="p">).</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="s1">'named'</span></pre>&#x000A;&#x000A;<h4 id=".names-contains-all-registered-mode-names-and-their-aliases">.names contains all registered mode names and their aliases</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'needle'</span><span class="p">,</span><span class="w"> </span><span class="ss">aliases:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">includes</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">names</span><span class="p">,</span><span class="w"> </span><span class="s1">'needle'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">includes</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">names</span><span class="p">,</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".register">.register<span class="arg-list">(spec)</span></h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-any-of-the-mandatory-inputs-are-missing">raises an error if any of the mandatory inputs are missing</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'name'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'create'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'foo'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".by_name">.by_name<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-mode-instance-for-&lt;name&gt;,-or-nil-if-not-existing">returns a mode instance for &lt;name&gt;, or nil if not existing</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'blargh'</span><span class="w">&#x000A;&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'shish'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'shish'</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="allows-looking-up-modes-by-any-aliases">allows looking up modes by any aliases</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'my_mode'</span><span class="w">&#x000A;&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'shish'</span><span class="p">,</span><span class="w"> </span><span class="ss">aliases:</span><span class="w"> </span><span class="p">{</span><span class="s1">'my_mode'</span><span class="p">},</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'my_mode'</span><span class="p">)</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="for_extension">for_extension<span class="arg-list">(extension)</span></h2>&#x000A;&#x000A;<h4 id="returns-a-mode-registered-for-&lt;extension&gt;,-if-any">returns a mode registered for &lt;extension&gt;, if any</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'ext'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ext'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_extension</span><span class="p">(</span><span class="s1">'foo'</span><span class="p">).</span><span class="n">name</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".for_file">.for_file<span class="arg-list">(file)</span></h2>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the file extension is registered with a mode)</span></h3>&#x000A;&#x000A;<h4 id="returns-an-instance-of-that-mode">returns an instance of that mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'ext'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'test.foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'ext'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="p">(</span><span class="n">file</span><span class="p">).</span><span class="n">name</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the file paths matches a mode pattern)</span></h3>&#x000A;&#x000A;<h4 id="returns-an-instance-of-that-mode">returns an instance of that mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'pattern'</span><span class="p">,</span><span class="w"> </span><span class="ss">patterns:</span><span class="w"> </span><span class="s1">'match%w+$'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'matchme'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'pattern'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="p">(</span><span class="n">file</span><span class="p">).</span><span class="n">name</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when the file header matches a mode shebang)</span></h3>&#x000A;&#x000A;<h4 id="returns-an-instance-of-that-mode">returns an instance of that mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'shebang'</span><span class="p">,</span><span class="w"> </span><span class="ss">shebangs:</span><span class="w"> </span><span class="s1">'lua$'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="nc">File</span><span class="p">.</span><span class="n">with_tmpfile</span><span class="w"> </span><span class="p">(</span><span class="n">file</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">file</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'#! /usr/bin/lua\nother line\nand other\n'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'shebang'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="p">(</span><span class="n">file</span><span class="p">).</span><span class="n">name</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when no matching mode can be found)</span></h3>&#x000A;&#x000A;<h4 id="returns-an-instance-of-the-mode-&quot;default&quot;">returns an instance of the mode &quot;default&quot;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">file</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'test.blargh'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'default'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="p">(</span><span class="n">file</span><span class="p">).</span><span class="n">name</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(mode creation)</span></h3>&#x000A;&#x000A;<h4 id="modes-are-created-by-calling-the-modes-create-function,-passing-the-name">modes are created by calling the modes create function, passing the name</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">create</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'callme'</span><span class="p">,</span><span class="w"> </span><span class="ss">:create</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'callme'</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">create</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="s1">'callme'</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="mode-configuration-variables">mode configuration variables</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'mode_var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'some var'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="s1">'def value'</span></pre>&#x000A;&#x000A;<h4 id="mode-instances-automatically-have-their-.config-set">mode instances automatically have their .config set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'config'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">mode_config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'config'</span><span class="p">).</span><span class="n">config</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">mode_config</span><span class="w">&#x000A;&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'def value'</span><span class="p">,</span><span class="w"> </span><span class="n">mode_config</span><span class="p">.</span><span class="n">mode_var</span><span class="w">&#x000A;</span><span class="n">mode_config</span><span class="p">.</span><span class="n">mode_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">mode_config</span><span class="p">.</span><span class="n">mode_var</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'def value'</span><span class="p">,</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">mode_var</span></pre>&#x000A;&#x000A;<h4 id="the-.config-is-pre-seeded-with-variables-from-.default_config-of-the-mode-(if-any)">the .config is pre-seeded with variables from .default_config of the mode (if any)</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'pre_config'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">default_config:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">mode_var:</span><span class="w"> </span><span class="mi">543</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">543</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'pre_config'</span><span class="p">).</span><span class="n">config</span><span class="p">.</span><span class="n">mode_var</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id="configure">configure<span class="arg-list">(mode_name, variables)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'user_configured'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span></pre>&#x000A;&#x000A;<h4 id="allows-setting-mode-specific-variables-automatically-upon-creation">allows setting mode specific variables automatically upon creation</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">configure</span><span class="w"> </span><span class="s1">'user_configured'</span><span class="p">,</span><span class="w"> </span><span class="ss">mode_var:</span><span class="w"> </span><span class="s1">'from_user'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'from_user'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'user_configured'</span><span class="p">).</span><span class="n">config</span><span class="p">.</span><span class="n">mode_var</span></pre>&#x000A;&#x000A;<h4 id="automatically-sets-the-config-variables-for-any-already-instantiated-mode">automatically sets the config variables for any already instantiated mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode_config</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'user_configured'</span><span class="p">).</span><span class="n">config</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">configure</span><span class="w"> </span><span class="s1">'user_configured'</span><span class="p">,</span><span class="w"> </span><span class="ss">mode_var:</span><span class="w"> </span><span class="s1">'after_the_fact'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'after_the_fact'</span><span class="p">,</span><span class="w"> </span><span class="n">mode_config</span><span class="p">.</span><span class="n">mode_var</span></pre>&#x000A;&#x000A;<h4 id="overrides-any-default-mode-configuration-set">overrides any default mode configuration set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'mode_with_config'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">default_config:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="ss">mode_var:</span><span class="w"> </span><span class="s1">'mode set'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">configure</span><span class="w"> </span><span class="s1">'mode_with_config'</span><span class="p">,</span><span class="w"> </span><span class="ss">mode_var:</span><span class="w"> </span><span class="s1">'user set'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'user set'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'mode_with_config'</span><span class="p">).</span><span class="n">config</span><span class="p">.</span><span class="n">mode_var</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="mode-inheritance">mode inheritance</h2>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">base</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">foo:</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'base'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">base</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'sub'</span><span class="p">,</span><span class="w"> </span><span class="ss">parent:</span><span class="w"> </span><span class="s1">'base'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;  </span><span class="n">config</span><span class="p">.</span><span class="n">define</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'delegated_mode_var'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'some var'</span><span class="p">,</span><span class="w"> </span><span class="ss">default:</span><span class="w"> </span><span class="s1">'def value'</span></pre>&#x000A;&#x000A;<h4 id="the-instantiated-mode-has-.parent-set-to-the-instantiated-parent">the instantiated mode has .parent set to the instantiated parent</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'base'</span><span class="p">),</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'sub'</span><span class="p">).</span><span class="n">parent</span></pre>&#x000A;&#x000A;<h4 id="a-mode-extending-another-mode-automatically-delegates-to-that-mode">a mode extending another mode automatically delegates to that mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'sub'</span><span class="p">).</span><span class="n">foo</span><span class="w">&#x000A; </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'base'</span><span class="p">).</span><span class="n">config</span><span class="p">.</span><span class="n">delegated_mode_var</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">123</span><span class="w">&#x000A; </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">123</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'sub'</span><span class="p">).</span><span class="n">config</span><span class="p">.</span><span class="n">delegated_mode_var</span></pre>&#x000A;&#x000A;<h4 id="an-error-is-raised-if-the-mode-indicated-by-parent-does-not-exist">an error is raised if the mode indicated by parent does not exist</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">assert</span><span class="p">.</span><span class="n">has_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'wrong'</span><span class="p">,</span><span class="w"> </span><span class="ss">parent:</span><span class="w"> </span><span class="s1">'keyser_soze'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;  </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'wrong'</span></pre>&#x000A;&#x000A;<h4 id="parent-defaults-to-&quot;default&quot;-unless-given">parent defaults to &quot;default&quot; unless given</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'orphan'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'default'</span><span class="p">),</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'orphan'</span><span class="p">).</span><span class="n">parent</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".unregister">.unregister<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<h4 id="removes-the-mode-specified-by-&lt;name&gt;">removes the mode specified by &lt;name&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'mode'</span><span class="p">,</span><span class="w"> </span><span class="ss">aliases:</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'zen'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'mode'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'mode'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">for_file</span><span class="p">(</span><span class="nc">File</span><span class="p">(</span><span class="s1">'test.zen'</span><span class="p">)),</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'default'</span></pre>&#x000A;&#x000A;<h4 id="removes-any-memoized-instance">removes any memoized instance</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'memo'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'memo'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">unregister</span><span class="w"> </span><span class="s1">'memo'</span><span class="w">&#x000A;</span><span class="n">live</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="w"> </span><span class="s1">'memo'</span><span class="w">&#x000A;</span><span class="n">mode</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'memo'</span><span class="p">,</span><span class="w"> </span><span class="ss">extensions:</span><span class="w"> </span><span class="s1">'memo'</span><span class="p">,</span><span class="w"> </span><span class="ss">create:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_equal</span><span class="w"> </span><span class="n">live</span><span class="p">,</span><span class="w"> </span><span class="n">mode</span><span class="p">.</span><span class="n">by_name</span><span class="p">(</span><span class="s1">'memo'</span><span class="p">)</span></pre>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
